package com.fqj.fqjinterface.controller;


import com.fqj.yuapiclientsdk.model.User;
import com.fqj.yuapiclientsdk.utils.SignUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.security.Signature;

/**
 * 名称API
 *
 *
 */
@RestController
@RequestMapping("/name")
public class NameController {

	@GetMapping("/woName")
	public String getNameByGet(String name,HttpServletRequest request){
		System.out.println(request.getHeader("fqj"));
		return "GET 你的名字是"+name;
	}

	@PostMapping("/")
	public String getNameByPost(@RequestParam String name){
		return "POST 你的名字是"+name;
	}

	@PostMapping("/user")
	public String getUserNameByPost(@RequestBody User user, HttpServletRequest request){
		// String accessKey = request.getHeader("accessKey");
		// String nonce = request.getHeader("nonce");
		// String timeStamp = request.getHeader("timeStamp");
		// String sign = request.getHeader("sign");
		// String body = request.getHeader("body");
		// //todo 实际情况应该去数据库查是否已分配给用户
		// if (!accessKey.equals("fqj")){
		// 	throw new RuntimeException("无权限");
		// }
		// if (Long.parseLong(nonce)>10000){
		// 	throw new RuntimeException("无权限");
		// }
		//todo 时间和当前时间不能超过5分钟
		// if (timeStamp)


		//todo 实际情况中是从数据库中查出 secretKey

		// String serverSign = SignUtils.getSign(body, "abcdefg");
		// if (!sign.equals(serverSign)){
		// 	throw new RuntimeException("无权限");
		// }

		String result = "POST 用户名字是" + user.getUsername();
		//调用次数 + 1
		return result;
	}
}
